output: html_document
# Create a leaflet map widget
leaflet() %>%
# Add default OpenStreetMap tiles to the map
addTiles() %>%
# Set the initial view of the map
setView(lng = -157.858333, lat = 21.306944, zoom = 10) %>%
# Add a marker for a specific location (Honolulu)
addMarkers(lng = -157.858333, lat = 21.306944, popup = "Aloha from Honolulu! 🌺")
# Read GeoJSON as sf object
ahupuaa_data <- st_read("data/Ahupuaa.geojson")
#> Reading layer `Ahupuaa' from data source
#> `/Users/kishi/Documents/Dev/ethnobotany-resources/data/Ahupuaa.geojson'
#> using driver `GeoJSON'
#> Simple feature collection with 727 features and 9 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: -160.247 ymin: 18.91069 xmax: -154.8066 ymax: 22.23529
#> Geodetic CRS: WGS 84
raingauge_data <- st_read("data/Rain_Gauges.geojson")
#> Reading layer `Rain_Gauges' from data source
#> `/Users/kishi/Documents/Dev/ethnobotany-resources/data/Rain_Gauges.geojson'
#> using driver `GeoJSON'
#> Simple feature collection with 1107 features and 97 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -159.7822 ymin: 18.91617 xmax: -154.82 ymax: 22.23135
#> Geodetic CRS: WGS 84
# Calculate centroids for labeling
centroids <- st_centroid(ahupuaa_data)
#> Warning: st_centroid assumes attributes are constant over geometries
# Create map
map <- leaflet() %>%
addTiles() %>%
setView(lng = -157.8583, lat = 20.9078, zoom = 7)
# Add ahupuaa polygons
map <- map %>%
addPolygons(
data = ahupuaa_data,
fillColor = "lightblue",
fillOpacity = 0.3,
color = "red",
weight = 2,
)
# Add markers at centroids
map <- map %>%
addMarkers(
data = centroids,
popup = ~paste0(
"<h3>", ahupuaa, "</h3>",
"<p><strong>Moku:</strong> ", moku, "</p>",
"<p><strong>Mokupuni:</strong> ", mokupuni, "</p>",
"<p><strong>Area:</strong> ", gisacres, " ac</p>"
),
label = ~ahupuaa
)
# Add raingauge circle markers
map <- map %>%
addCircleMarkers(
data = raingauge_data,
group = "Raingauges",
radius = 8,
fillColor = "blue",
color = "white",
weight = 2,
fillOpacity = 0.8,
popup = ~paste0(
"<h3>", name, "</h3>",
"<p><strong>Elevation:</strong> ", elevft, "</p>",
"<p>", stationsta, "</p>"
))
map